/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} headA
 * @param {ListNode} headB
 * @return {ListNode}
 */

var getIntersectionNode = function (headA, headB) {
    let curA = headA
    let curB = headB
    while (curA) {
        while (curB) {
            if (curA === curB) {
                return curA
            } else {
                curB = curB.next
            }
        }
        curB = headB
        curA = curA.next
    }
    return null
};